﻿using Microsoft.EntityFrameworkCore;

namespace TowerCraneMonitorClient.NetClient
{
    public class EntityContext : DbContext
    {
        public DbSet<MoniterInfo.Entity> MoniterInfos { get; set; }
        public DbSet<DriverInfo.Entity> DriverInfos { get; set; }
        public DbSet<RunData.Entity> RunDatas { get; set; }
        public DbSet<WorkCycle.Entity> WorkCycles { get; set; }
        public DbSet<ReserveInfo.Entity> ReserveInfos { get; set; }
        public DbSet<BasicInfo.Entity> BaseicInfos { get; set; }
        public DbSet<LimitInfo.Entity> LimitInfos { get; set; }
        public DbSet<EventAlarm.Entity> EventAlarms { get; set; }
        public DbSet<EventFault.Entity> EventFaults { get; set; }
        //public DbSet<EventAlarm.Message> EventAlarmMessages { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder options)
        {
            options.UseSqlite("Data Source=Client.sqlite3");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<EventAlarm.Entity>()
                .HasOne(a => a.EventMessage)
                .WithOne(m => m.EventAlarm)
                .HasForeignKey<EventAlarm.EventMessage>(a => a.EventAlarmId)
                //.HasForeignKey<EventAlarm.Entity>(m => m.EventMessageId)
                .OnDelete(DeleteBehavior.Cascade);
        }
    }
}
